package com.fr.report.js;

import com.fr.base.FCloneable;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.BaseXMLUtils;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.data.DBManipulation;
import com.fr.report.io.xml.ReportXMLUtils;
import com.fr.web.Repository;

public class Commit2DBJavaScript extends AbstractJavaScript
  implements CallBackable
{
  private DBManipulation dbManipulation;
  private JavaScript callBack;

  public DBManipulation getDBManipulation()
  {
    return this.dbManipulation;
  }

  public void setDBManipulation(DBManipulation paramDBManipulation)
  {
    this.dbManipulation = paramDBManipulation;
  }

  public JavaScript getCallBack()
  {
    return this.callBack;
  }

  public void setCallBack(JavaScript paramJavaScript)
  {
    this.callBack = paramJavaScript;
  }

  public String createJS(Repository paramRepository)
  {
    return "this.options.form.dbCommit({xmlconf:" + JSONObject.quote(BaseXMLUtils.writeXMLableAsString(this.dbManipulation)) + "," + "callback:function(res) {" + ((this.callBack != null) ? this.callBack.createJS(paramRepository) : "") + "}" + "})";
  }

  public String toString()
  {
    return ((this.dbManipulation == null) ? "" : this.dbManipulation.toString());
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    super.writeXML(paramXMLPrintWriter);
    if (this.dbManipulation != null)
      this.dbManipulation.writeXML(paramXMLPrintWriter);
    if (this.callBack != null)
      ReportXMLUtils.writeXMLable(paramXMLPrintWriter, this.callBack, "JavaScript");
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isAttr())
    {
      this.dbManipulation = new DBManipulation();
    }
    else if (paramXMLableReader.isChildNode())
    {
      String str = paramXMLableReader.getTagName();
      if ("JavaScript".equals(str))
        this.callBack = ReportXMLUtils.readJavaScript(paramXMLableReader);
      else
        this.dbManipulation.readXML(paramXMLableReader);
    }
  }

  public boolean equals(Object paramObject)
  {
    return ((paramObject instanceof Commit2DBJavaScript) && (super.equals(paramObject)) && (((Commit2DBJavaScript)paramObject).callBack.equals(this.callBack)) && (((Commit2DBJavaScript)paramObject).dbManipulation.equals(this.dbManipulation)));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    Commit2DBJavaScript localCommit2DBJavaScript = (Commit2DBJavaScript)super.clone();
    if (this.dbManipulation != null)
      localCommit2DBJavaScript.dbManipulation = ((DBManipulation)this.dbManipulation.clone());
    if (this.callBack != null)
      localCommit2DBJavaScript.callBack = ((JavaScript)this.callBack.clone());
    return localCommit2DBJavaScript;
  }
}